<?php
/**
 * Author:xsc
 * Time:2023/11/20 17:58
 */

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Common\Constant;
use App\Extensions\Common\RedisService;
use App\Jobs\ModifySpecialCallbackJob;
use Illuminate\Support\Facades\Log;

class ModifySpecialCallback extends Command
{

    /**
     * 命令名称
     */
    protected $signature = 'modify_special_callback';

    /**
     * 命令描述
     */
    protected $description = '藏品状态更新回调';

    /**
     * 创建命令
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 执行命令
     */
    public function handle()
    {
        $time = time();
        $redis = RedisService::getInstance();
        $key = Constant::MODIFY_SPECIAL_CALLBACK;

        while (1) {
            if (time() > $time + 59) {
                break;
            }

            $special_id = $redis->lIndex($key, 0);

            if ($special_id) {
                Log::info('[藏品状态更新回调]脚本' . $special_id);

                // 异步队列里面执行
                dispatch(new ModifySpecialCallbackJob($special_id));
                $redis->lPop($key);
            } else {
                sleep(1);
                //usleep(500000);
            }
        }
    }
}
